package com.example.admin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.admin.dao.AdSensitiveDao;
import com.example.admin.service.SensitiveService;
import com.usian.model.admin.dtos.SensitiveDto;
import com.usian.model.admin.pojos.AdSensitive;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
@Slf4j
public class SensitiveServiceImpl implements SensitiveService {

    @Autowired
    private AdSensitiveDao adSensitiveDao;
    @Override
    public List<AdSensitive> getSensitiveByName(SensitiveDto sensitiveDto) {
        //校验

        LambdaQueryWrapper<AdSensitive> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(AdSensitive::getSensitives,sensitiveDto.getName());
        IPage<AdSensitive> page = new Page<>(sensitiveDto.getPage(),sensitiveDto.getSize());
        IPage<AdSensitive> pageSensitive = adSensitiveDao.selectPage(page, lambdaQueryWrapper);
        return pageSensitive.getRecords();
    }

    @Override
    public Integer addSensitive(SensitiveDto sensitiveDto) {
        AdSensitive adSensitive = new AdSensitive();
        adSensitive.setCreatedTime(new Date());
        BeanUtils.copyProperties(sensitiveDto,adSensitive);
        return adSensitiveDao.insert(adSensitive);
    }
}
